package org.one.stone.soup.grfxML.plugin.image;

import java.awt.Color;

import org.one.stone.soup.grfxML.DataColor;
import org.one.stone.soup.grfxML.DataImage;
import org.one.stone.soup.grfxML.DataPoint;
import org.one.stone.soup.grfxML.GeometryImage;
import org.one.stone.soup.grfxML.GrfxMLEngine;
import org.one.stone.soup.grfxML.plugin.SimplePlugin;
import org.one.stone.soup.grfxML.plugin.grfxMLCaster;
import org.one.stone.soup.mjdb.data.field.DataLinker;
import org.one.stone.soup.mjdb.data.field.Field;

public class VGrad extends SimplePlugin {

	public static final int ARG_IMAGE = 0;

	public static final int ARG_SIZE = 1;

	public static final int ARG_COLOR_A = 2;

	public static final int ARG_COLOR_B = 3;

	DataColor colorA = new DataColor();
	DataColor colorB = new DataColor();
	DataImage image = new DataImage();
	DataPoint size = new DataPoint();

/**
 * SimpleImageButton constructor comment.
 */
public VGrad (GrfxMLEngine engine){
	super(engine);
}
/**
 * initialize method comment.
 */
public void initialize()
{
	Color newColorA = new Color(
		colorA.getValueX(),
		colorA.getValueY(),
		colorA.getValueZ(),
		colorA.alpha
	);

	Color newColorB = new Color(
		colorB.getValueX(),
		colorB.getValueY(),
		colorB.getValueZ(),
		colorB.alpha
	);

	((GeometryImage)image.getGeometry(getEngine())).setImage(
				org.one.stone.soup.grfx.ImageFactory.createVGradImage(
						newColorA,
						newColorB,
						size.getValueX(),
						size.getValueY()
					)
			);
}
/**
 * process method comment.
 */
public void process()
{
	if(size.hasChanged() || colorA.hasChanged() || colorB.hasChanged())
	{
		Color newColorA = new Color(
			colorA.getValueX(),
			colorA.getValueY(),
			colorA.getValueZ(),
			colorA.alpha
		);

		Color newColorB = new Color(
			colorB.getValueX(),
			colorB.getValueY(),
			colorB.getValueZ(),
			colorB.alpha
		);

		((GeometryImage)image.getGeometry(getEngine())).setImage(
					org.one.stone.soup.grfx.ImageFactory.createVGradImage(
							newColorA,
							newColorB,
							size.getValueX(),
							size.getValueY()
						)
				);
	}
}
/**
 * register method comment.
 */
public void register(DataLinker store)
{
	colorA = grfxMLCaster.cast(colorA,getArg(colorA,ARG_COLOR_A,store));

	colorB = grfxMLCaster.cast(colorB,getArg(colorB,ARG_COLOR_B,store));

	image = grfxMLCaster.cast(image,getArg(image,ARG_IMAGE,store));

	size = grfxMLCaster.cast(size,getArg(size,ARG_SIZE,store));

}
/**
 * replace method comment.
 */
public void replace(Field oldObj, Field newObj)
{
	image = grfxMLCaster.replace(image,oldObj,newObj);
	size = grfxMLCaster.replace(size,oldObj,newObj);
	colorA = grfxMLCaster.replace(colorA,oldObj,newObj);
	colorB = grfxMLCaster.replace(colorB,oldObj,newObj);
}
/**
 * stop method comment.
 */
public void stop() {}
}
